<template>
  <view class="content">
    <!-- 公共组件-每个页面必须引入 -->
    <public-module></public-module>
	<div class="add-inquiry-page">
		<div v-if="storeUserInfo.isBuyerAuth != 1" style="margin-bottom:10rpx">
			<u-alert title="认证后才能发起询价" type = "warning"></u-alert>
		</div>
		<div class="inquiry-block">
			<div class="inquiry-text">点击牌号导入询价内容</div>
			<scroll-view :scroll-top="scrollTop" :scroll-y="overflow"  class="inquiry-history-list" :style="{'max-height':height}" @scroll="scroll">
				<div class="list-item" v-for="(item,index) in history" :key="index" @click="importInquiry(item)">{{item.parentCategoryName}}/{{item.categoryName}}/{{item.brandName}}{{item.goodsSn}}</div>
			</scroll-view>
		
			<div class="inquiry-btn" @click="changeHeight" v-if="history && history.length > 4">
				<span style="padding-right:5px">{{!overflow ? '点击查看更多历史牌号' : '收起'}}</span>
				<u-icon :name="!overflow ? 'arrow-down' : 'arrow-up' "></u-icon>
			</div>
		</div>
		<div class="inquiry-block" style="margin-top:18rpx">
			<div class="index-form">
				<u--form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth="100" errorType="toast">
					<!--第一步-->
					<div v-show="step == 1">
						<div class="form-div">
							<u-form-item label="品名"  required  @click="showCategory" ref="item1" prop="categoryName">
								<u--input fontSize="14" inputAlign="right" :value="firstName + (firstName != '' ? '/' : '' )+ form.categoryName" disabled disabledColor="none" placeholder="请选择品名" border="none" style="pointer-events: none"></u--input>
								<div slot="right" class="form-icon">
									<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
								</div>
							</u-form-item>
						</div>
							
						<div class="form-div" v-if="form.categoryName == '' || (form.categoryName != '' && (firstName.indexOf('原') != -1 || firstName.indexOf('改') != -1))">
							<u-form-item label="厂家牌号"  required  @click="showGoods" ref="item1" prop="goodsSn">
								<u--input fontSize="14" inputAlign="right" :value="form.brandName+form.goodsSn" disabled disabledColor="none" placeholder="请选择牌号" border="none" style="pointer-events: none"></u--input>
								<div slot="right" class="form-icon">
									<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
								</div>
							</u-form-item>
						</div>	
						
						<div class="form-div" v-if="firstName.indexOf('定') != -1">
							<u-form-item label="分类属性"  required  @click="showAttr" ref="item1"  prop="goodsFunction">
								<u--input fontSize="14" inputAlign="right" :value="form.goodsFunction" disabled disabledColor="none" placeholder="请选择分类属性,可多选" border="none" style="pointer-events: none"></u--input>
								<div slot="right" class="form-icon">
									<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
								</div>
							</u-form-item>
						</div>
							
						<div class="form-div" v-if="firstName.indexOf('再') != -1">
							<u-form-item label="颜色"  required  @click="showColor" ref="item2"  prop="goodsColor">
								<u--input fontSize="14" inputAlign="right" :value="form.goodsColor" disabled disabledColor="none" placeholder="请选择颜色" border="none" style="pointer-events: none"></u--input>
								<div slot="right" class="form-icon">
									<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
								</div>
							</u-form-item>
						</div>	
							
					</div>
					
					<!--第二步-->
					<div v-show="step > 1">
						<div class="form-div">
							<u-form-item  required label="询价数量" >
								<u--input  fontSize="14" inputAlign="right" v-model="form.goodsNum" border="none"  placeholder="请输入数量" @blur="upGoodsNum"></u--input>
								<span slot="right" style="padding-left:20rpx;font-size: 14px;">(吨)</span>
							</u-form-item>
						</div>	
							
						
						<div class="form-div" style="margin-bottom: 0;">
							<u-form-item  required label="收货区域" >
								<uni-data-picker v-slot:default placeholder="请选择所在地区" popup-title="请选择所在地区" :localdata="dataTree"
								  :map="{text:'areaName',value:'areaId'}" @change="onchange" @popupopened="onpopupopened"
								  :modelValue="form.receiveAreaId"
								  @popupclosed="onpopupclosed" :clear-icon="false" style="width:100%" ref="picker">
								  <view class="form-row">
									<view class="input" style="display: block;" v-if="form.areaInfo != ''"> {{form.areaInfo}}</view>
									<view v-else><text style="color:#c0c4cc">请选择所在地区</text></view>
									<div class="form-icon">
										<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
									</div>
								  </view>
								</uni-data-picker>
							</u-form-item>
						</div>
							
						<!--第三步-->
						
						<div v-show="step == 3">
							<!-- <u-form-item  required label="结算方式" borderBottom prop="payTypes">
								<u-radio-group v-model="form.payTypes" placement="row">
									<u-radio activeColor="#FF5E01" label="现汇" name="现汇"></u-radio>
									<div style="width:20px;"></div>
									<u-radio activeColor="#FF5E01" label="承兑" name="承兑"></u-radio>
								</u-radio-group>
							</u-form-item> -->
							<u-form-item  required label="收货方式" prop="sendTypes">
								<u-radio-group v-model="form.sendTypes" placement="row">
									<u-radio activeColor="#FF5E01" label="自提" name="自提"></u-radio>
									<div style="width:20px;"></div>
									<u-radio activeColor="#FF5E01" label="送到" name="送到"></u-radio>
								</u-radio-group>
							</u-form-item>
							<div class="form-div block-color">
								<u-form-item label="交货日期"   @click="showDate('receiveDate')">
									<u--input fontSize="14" inputAlign="right" :value="form.receiveDate" disabled disabledColor="none" placeholder="请选择交货日期" border="none" style="pointer-events: none"></u--input>
									<div slot="right" class="form-icon">
										<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
									</div>
								</u-form-item>
							</div>
							<div class="form-div block-color">
								<u-form-item label="截止时间"   @click="showDate('endTime')">
									<u--input fontSize="14" inputAlign="right" :value="form.endTime" disabled disabledColor="none" placeholder="请选择截止时间" border="none" style="pointer-events: none"></u--input>
									<div slot="right" class="form-icon">
										<u-icon name="arrow-right" color="#FF5E01" size="10" bold></u-icon>
									</div>
								</u-form-item>
							</div>
							
						</div>
					</div>
					
					
					
					
					<!-- <div class="block-color">
						<u-form-item label="补充说明"  labelPosition="top">
							<div style="padding-top:20rpx;width:100%">
								<u--textarea v-model="form.inquiryRemark" placeholder="请输入内容" ></u--textarea>
							</div>
						</u-form-item>
					</div>		
	 -->
				</u--form>
				
				<div style="margin-top:40rpx;" >
					<div class="form-btn">
						<!--:disabled="storeUserInfo.isBuyerAuth != 1">-->
						<u-button text="确认" :color="mobileBtnColor" shape="circle" @click="nextStep"  v-if="step == 1"></u-button>
						<u-button text="继续完善" :plain="true" :color="mobileBtnColor" :customStyle="style4" shape="circle"  @click="step = 3"  v-if="step == 2"></u-button>
						<u-button text="上一步"  :plain="true" :color="mobileBtnColor" :customStyle="style4" shape="circle"  @click="step = 1"  v-if="step == 3"></u-button>
						<div style="width:40rpx" v-if="step != 1"></div>
						<u-button text="发布询盘" :color="mobileBtnColor" shape="circle" :loading="btnloading" @click="addForm"  v-if="step != 1"></u-button>
					    <!-- #ifdef H5-->
						 <div class="form-btn-div" @click="showUpload" style="width:200rpx;margin-left:20rpx;">
					     	<img src="	https://pic.moresu.com/FvcalzMSFCaisgFC46DivmkoS_4k" style="width:40rpx;height:40rpx;display: inline-block;"/>
					     	<div class="btn-label" style="font-size: 24rpx;white-space: nowrap;">上传订单需求</div>
					     </div>
						 <!-- #endif -->
					</div>
				
					<!-- #ifdef MP | APP-PLUS-->
					<div class="form-btn" style="margin-top:40rpx;justify-content:center">
						<div class="form-btn-div"  @click="showAudio" style="width:200rpx">
							<img src="https://pic.moresu.com/Fm8rH-mQCRtz-9F3-njtCG5wOBFf" style="width:40rpx;height:40rpx;display: inline-block;"/>
							<div class="btn-label" style="font-size: 24rpx;">说出你的需求</div>
						</div>
						<div style="width:40rpx;height:70rpx;border-left:1px solid #eee;margin-left:40rpx;"></div>
						<div class="form-btn-div" @click="showUpload" style="width:200rpx">
							<img src="	https://pic.moresu.com/FvcalzMSFCaisgFC46DivmkoS_4k" style="width:40rpx;height:40rpx;display: inline-block;"/>
							<div class="btn-label" style="font-size: 24rpx;">上传订单需求</div>
						</div>
					</div>
					<!-- #endif -->
					
				</div>
				
			</div>
		</div>
	</div>
	
	
	<!--品名-->
	<category ref="category" @chooseItem="chooseCategory"></category>
	
	<!--牌号厂家-->
	<goodsSn ref="goodsSn" @chooseItem="chooseGoodsSn" @blackCategory="blackCategory"></goodsSn>
	
	<!--颜色-->
	<chooseColor ref="chooseColor" @chooseItem="chooseColor" @blackCategory="blackCategory"></chooseColor>
	
	<!--属性-->
	<chooseAttr ref="chooseAttr" @chooseItem="chooseAttr" @blackCategory="blackCategory"></chooseAttr>
	
	<!--时间选择-->
	<u-datetime-picker v-if="showTime" :minDate="minDate" :show="showTime" v-model="value1" :mode="mode1"  @confirm="confirmTime" @cancel="showTime=false" closeOnClickOverlay @close="showTime=false"></u-datetime-picker>
	
    <!--音频-->
    <audioo ref="audioo" @showResult="showResult"></audioo>
	
	
	<!--询价结果-->
	<result ref="result"></result>
	
	<!--上传文件-->
	<uploadFile ref="uploadFile" @showResult="showResult"></uploadFile>
	
	
	
	<f-tabbar  ref="fTabbar"></f-tabbar>
	
	<!-- <driver-page ref="driverPage"></driver-page> -->
	
  </view>
</template>

<script>
  import fTabbar from '@/components/module/f-tabbar/f-tabbar';
  import {getAreaList,addInquiry,messageSetView,messageList,shareCode,adList,checkStoreStatus,getGuideDataAPI,settingInfo,historyInquiryData,priceMappingDetail,lastInquiry,pageSeo,goodsInfo,topicSubClassList,setScanCodeLog} from '@/config/api.js'
  import category from '@/components/module/category';
  import goodsSn from '@/components/module/goodsSn';
  import audioo from '@/components/module/audio'
  import result from '@/components/module/result'
  import chooseColor from '@/components/module/chooseColor'
  import chooseAttr from '@/components/module/chooseAttr'
  import driverPage from '@/components/driver-page/driver-page';
  import uploadFile from '@/components/module/uploadFile';
  import{saveShareUid,getAppLatLon,saveSource}  from '@/plugins/utils.js'
  import store from '@/store';
   const log = require('@/plugins/log.js')
  const defaultForm={
  	     "inquiryType" : "exact", //精准询价
		 "categoryId" : '',    //分类ID
		 "categoryName":'',
		 "brandId" : '',       //厂家ID
		 "brandName":'',
		 "goodsSn" : "", //商品牌号   
		 "goodsNum" : '',     //询价数量    
		 "receiveDate" : "", //交货日期
		 "receiveAreaId" : '', //交货地区ID   
		 areaInfo:'',
		 endTime:'',
		 goodsColor:'',
		 goodsFunction:'',
		 inquiryRemark:'',
		 payTypes:'现汇',
		 sendTypes:'送到',
      };
  export default {
    components: {
      fTabbar,category,goodsSn,audioo,result,chooseColor,chooseAttr,driverPage,uploadFile
    },
    data() {
      return {
        voicePath: '',
		style:{
			height: '70rpx',
			borderRadius: '18rpx',
			flex:1,
			paddingRight:'40rpx'
		},
		style2:{
			width:'180rpx',
			height:'70rpx',
			borderRadius: '18rpx',
			marginLeft:'-20rpx',
			boxShadow: 'inset 0rpx 2rpx 5px rgba(0,0,0,0.1)',
		},
		dataTree: [],
		showMore:false,
		showTime:false,
	    value1: '',
		mode1:'',
		key:'',
		form:JSON.parse(JSON.stringify(defaultForm)),
		rules:{
			categoryName: [{
					required: true,
					message: '请选择品名',
					// 可以单个或者同时写两个触发验证方式
					trigger: ['blur', 'change']
				}],
			goodsSn: [{
					required: true,
					message: '请选择厂家牌号',
					// 可以单个或者同时写两个触发验证方式
					trigger: ['blur', 'change']
				}],
			goodsColor: [{
					required: true,
					message: '请选择颜色',
					// 可以单个或者同时写两个触发验证方式
					trigger: ['blur', 'change']
				}],
			goodsFunction: [{
					required: true,
					message: '请选择分类属性',
					// 可以单个或者同时写两个触发验证方式
					trigger: ['blur', 'change']
				}],
			payTypes: [{
					required: true,
					message: '请选择结算方式',
					// 可以单个或者同时写两个触发验证方式
					trigger: [ 'change']
				}],
			sendTypes: [{
					required: true,
					message: '请选择收货方式',
					// 可以单个或者同时写两个触发验证方式
					trigger: ['change']
				}],
		},
		btnloading:false,
		inquiryId:'',
		
		list:[],
		intellectContent:'',
		areaData:[],
		shareTitle:'',
		qrCode:'',
		shareImage:'',
		firstName:'',
		firstId:'',
		minDate:Number( new Date()),
		list1:[],
		style3:{
			height:'44rpx',
		},
		text1:'',
		steps:[],
		mobileBackgroundImg:'',
		mobileBtnColor:'linear-gradient(180deg, #FF8641 0%, #FF5E01 100%)',
		history:[],
		height:'100rpx',
		overflow:false,
		scrollTop:0,
		old: {
			scrollTop: 0
		},
		storeUserInfo:{},
		step:1,
		style4:{
			border:'1px solid #FF8641',
			color:'#FF8641'
		
		},
		// specialId:''
		
      }
    },
	onPageScroll(res){
			// this.$refs.driverPage.setScroll(res.scrollTop)
			
	},
    async onLoad(options) {
		// 隐藏原生的tabbar
		uni.hideTabBar();
    	await this.$onLaunched;
	  this.getDataList();
	  this.getCode();
	  
      let self = this;
	  if(options.scene) { //分享进入
		  var splitStr = unescape(options.scene).split(",");
		  console.log(splitStr)
		  let pcodeIndex = splitStr.findIndex((item)=>{
				return item.indexOf('pcode') != -1
		  })
		  splitStr.forEach((el) => {
			if (el.indexOf('pcode') != -1) {
			  let shareArry = el.split(":");
			  let pcode = shareArry[1];
			  saveShareUid(pcode);
			}
			if (el.indexOf('source') != -1) {
			  let sourceArry = el.split(":");
			  let source = sourceArry[1];
		      let pcode = ''
			  if(pcodeIndex != -1){
				  let shareArry = splitStr[pcodeIndex].split(":");
				  pcode = shareArry[1];
			  }
			  saveSource({source:source,pcode:pcode});
			  setScanCodeLog({source:source,pcode:pcode})
			}
		  });
		}
		// console.log("options",options)
		if(options.pcode){
		  saveShareUid(options.pcode)
		}
		
		// adList({adPosition:'index_swipe',adSource:1}).then((res)=>{
		// 	this.list1 = res;
		// })
		// checkStoreStatus().then((res)=>{
		// 	this.text1 = res
		// })
		settingInfo().then((res)=>{
			// this.mobileBackgroundImg = res.mobileBackgroundImg;
			// this.mobileBtnColor = res.mobileBtnColor;
			// this.style.border =  '2rpx solid'+ res.mobileBtnColor +'!important'
			// this.$refs.fTabbar.activeColor = res.mobileBtnColor
		})
		
		
    },
	async onShow() {
		await this.$onLaunched;
		this.storeUserInfo = store.state.userInfo;
		this.step = 1
		// this.specialId = ''
		this.$nextTick(()=>{
			// getGuideDataAPI({
			// 	pageUrl:'index'
			// }).then((res)=>{
			// 	this.steps=res
			// 	this.$refs.driverPage.showPop(this.steps)
			// }).catch((error)=>{
			// 	console.log(error)
			// })
		})
		
		checkStoreStatus().then((res)=>{
			this.text1 = res
		})
		this.gethistory();
		let pmId = getApp().globalData.pmId;
		let goodsId =  getApp().globalData.goodsId;
		// let specialId = getApp().globalData.specialId;
		// getAppLatLon(this.successCallback, this.errCallback, true)
		if(goodsId){
			getApp().globalData.goodsId = '';
			goodsInfo({goodsId:goodsId}).then((res)=>{
				this.form = JSON.parse(JSON.stringify(defaultForm))
				this.firstName = res.parentCategoryName;
				this.firstId = res.parentCategoryId;
				this.form.categoryId = res.categoryId;
				this.form.categoryName = res.categoryName;
				this.form.brandId = res.brandId;
				this.form.brandName = res.brandName;
				this.form.goodsSn = res.goodsSn;
				this.defaultTime()
			})
			
		}else if(pmId){  // 有牌号信息调用接口
			getApp().globalData.pmId = '';
			priceMappingDetail({pmId:pmId}).then((res)=>{
				this.form = JSON.parse(JSON.stringify(defaultForm))
				this.firstName = res.parentCategoryName;
				this.firstId = res.parentCategoryId;
				this.form.categoryId = res.categoryId;
				this.form.categoryName = res.categoryName;
				this.form.brandId = res.brandId;
				this.form.brandName = res.brandName;
				this.form.goodsSn = res.goodsSn;
				this.defaultTime()
			})
		}else {
			lastInquiry().then((res)=>{
				this.form = JSON.parse(JSON.stringify(defaultForm))
				      if(res){
				        this.firstName = res.parentCategoryName;
				        this.firstId = res.parentCategoryId;
				        this.form.categoryId = res.categoryId;
				        this.form.categoryName = res.categoryName;
				        this.form.brandId = res.brandId;
				        this.form.brandName = res.brandName;
				        this.form.goodsSn = res.goodsSn;
				        this.form.goodsNum = res.goodsNum;
				        this.form.receiveAreaId = res.receiveAreaId;
				        this.form.areaInfo = res.receiveArea;
				        this.form.payTypes = res.payTypes;
				        this.form.sendTypes = res.sendTypes;
				        this.defaultTime()
				      }
			})	
		}
		// #ifdef H5
		pageSeo({pageType: 'indexPage'}).then((res)=>{
			document.title = res.pageTitle;
		})
		// #endif
	},
	
	
    methods: {
		nextStep(){
			this.$refs.form.validateField(['categoryName','goodsSn','goodsColor','goodsFunction'],(errorsRes)=>{
				if(errorsRes.length == 0){
					this.step = 2
				}else {
			        uni.showToast({
			          title: errorsRes[0]['message'],
			          duration: 1000,
			          icon: 'none'
			        })
				}
			})
		},
		
		successCallback(res){
			console.log("位置信息",res)
		},
		errCallback(err){
			console.log(err,'err')
		},
		scroll: function(e) {
			console.log(e)
			this.old.scrollTop = e.detail.scrollTop
		},
		//导入询价
		importInquiry(item){
			this.firstName = item.parentCategoryName;
			this.firstId = item.parentCategoryId;
			this.form.categoryId = item.categoryId;
			this.form.categoryName = item.categoryName;
			this.form.brandId = item.brandId;
			this.form.brandName = item.brandName;
			this.form.goodsSn = item.goodsSn;
			this.form.goodsNum = item.goodsNum;
			this.form.receiveAreaId = item.receiveAreaId;
			this.form.areaInfo = item.receiveArea;
			this.form.payTypes = item.payTypes;
			this.form.sendTypes = item.sendTypes;
			this.defaultTime()
			
		},
		
		//切换历史询价高度
		changeHeight(){
			this.height = this.height == '100rpx' ? '200rpx' : '100rpx';
			this.scrollTop = this.old.scrollTop
			this.$nextTick(function() {
				this.scrollTop = 0
				this.overflow = !this.overflow;
			});
			
		},
		
		//获取历史询价
		gethistory(){
			historyInquiryData({pageSize:100,pageNum:1}).then((res)=>{
				this.history = res
			})
		},
		
		
		getCode(){
			shareCode({shareType:'mainPage'}).then((res)=>{
				this.shareTitle = res.shareTitle;
				this.qrCode = res.qrCode;
				this.shareImage = res.shareImage;
			})
		},
		
		
		upGoodsNum(){
			log.info('精准询价&询价数量&'+this.form.goodsNum);
		},
		showMoreFn(){
			this.showMore = true;
			log.info('精准询价&更多需求');
		},
		upInfo(key){
			log.info(key)
		},
		//显示结果
		showResult(res){
			// console.log("999999999",res)
			this.$refs.result.showResult(res)
		},
		
		// 显示文件上传
		showUpload(){
			let self = this
			self.judgeLogin(() => {
				self.judgeBuyerAuth(()=>{
					let storeUserInfo = store.state.userInfo;
					self.$refs.uploadFile.init();
				})
				
				// if(storeUserInfo.noAuthMsg != ''){
				// 	uni.showModal({
				// 		title: '提示',
				// 		confirmText:'关闭',
				// 		showCancel:false,
				// 		content: storeUserInfo.noAuthMsg,
				// 		success: function (res) {
							
				// 		}
				// 	});
				// 	return false
				// }
			})
			
				
		},
		
		showAudio(){
			let self = this;
			let text = '智能询价&语音询价按钮'
			// #ifdef MP-WEIXIN
		    log.info(text)
			// #endif
			 self.judgeLogin(() => {
				 self.judgeBuyerAuth(()=>{
					 let storeUserInfo = store.state.userInfo;
					 				// if(storeUserInfo.noAuthMsg != ''){
					 				// 	uni.showModal({
					 				// 		title: '提示',
					 				// 		confirmText:'关闭',
					 				// 		showCancel:false,
					 				// 		content: storeUserInfo.noAuthMsg,
					 				// 		success: function (res) {
					 							
					 				// 		}
					 				// 	});
					 				// 	return false
					 				// }
									// #ifdef MP-WEIXIN
					 				 uni.authorize({
					 				     scope: 'scope.record',
					 				     success() {
					 						self.$refs.audioo.init();
					 				     },
					 				 	fail(){
					 				 		uni.showModal({
					 				 			content: '检测到您没打开录音功能权限，是否去设置打开？',
					 				 			confirmText: "确认",
					 				 			cancelText: '取消',
					 				 			success: (res) => {
					 				 				if (res.confirm) {
					 				 					uni.openSetting({//opensetting是调起设置页面的
					 				 						success: (res) => {
					 				 							// console.log(res.authSetting);
					 				 						}
					 				 					})
					 				 				} else {
					 				 					// console.log('取消');
					 				 					return false;
					 				 				}
					 				 			}
					 				 		})
					 				 		return false;
					 				 	}
					 				 })
									 // #endif
									 // #ifdef APP-PLUS
									  self.$refs.audioo.init();
									 // #endif
					 },'inquiry');	
				 })
				
		},
		//提交精确询价
		addForm(){
			this.judgeLogin(() => {
				this.judgeBuyerAuth(()=>{ 
					let storeUserInfo = store.state.userInfo;
					// if(storeUserInfo.noAuthMsg != ''){
					// 	uni.showModal({
					// 		title: '提示',
					// 		confirmText:'关闭',
					// 		showCancel:false,
					// 		content: storeUserInfo.noAuthMsg,
					// 		success: function (res) {
								
					// 		}
					// 	});
					// 	return false
					// }
					this.$refs.form.validate().then(res => {
						let reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
						if(this.form.goodsNum == ''){
							uni.showToast({
							  title: '请输入数量',
							  duration: 1000,
							  icon: 'none'
							})
							return false
						}else if(!reg.test(this.form.goodsNum) && this.form.goodsNum !== ''){
							uni.showToast({
							  title: '输入数据不合法，请输入正数',
							  duration: 1000,
							  icon: 'none'
							})
							return false
						}
							
						if(this.form.receiveAreaId == ''){
							uni.showToast({
							  title: '请选择收货地区',
							  duration: 1000,
							  icon: 'none'
							})
							return false
						}
					   this.btnLoading = true;
					   let  data = JSON.parse(JSON.stringify(this.form));
					     data.parentCategoryId = this.firstId
						 addInquiry(data).then((res)=>{
							   this.btnLoading = false;
							   this.form = JSON.parse(JSON.stringify(defaultForm));
							   this.firstName = '';
							   this.firstId ='';
							   this.showMore = false
							   this.showResult(res)
							   let text = '精准询价&提交精准询价按钮&'+ JSON.stringify(data)
							   log.info(text)
							   // #ifdef MP-WEIXIN
							   wx.requestSubscribeMessage({
							     tmplIds: ['X6m-lruMVe4rf8tMEbcv-nxEeLSWbV9b6TX193jeeKE','R7bgDnCd2c3RcHZvAGVNWmJgmI-AxwL-aUqcGsIpkL4','WF5ac-NgWgW_qSYWsq7hRALuGZtmmvYf9jFsG4w61CA'],
							     success (res) {
							   			
							   		},
							   		fail(res){
							   			// console.log("res",res)
							   		},
							   		complete(){
							   			// console.log("89646456")
							   		}
							   })
							   // #endif
						 }).catch(()=>{
							   this.btnLoading = false;
						 })
					}).catch(errors => {
						
					})
				})
				
			},'inquiry')	
		},
		showAttr(){
			let text = '精准询价&分类属性选择按钮'
			log.info(text)
			this.$refs.chooseAttr.init(this.form.goodsFunction,this.firstId);
		},
		chooseAttr(e){
			this.form.goodsFunction = e.join(",");
		},
		showColor(){
			let text = '精准询价&颜色选择按钮'
			log.info(text)
			this.$refs.chooseColor.init(this.form.goodsColor,this.firstId);
		},
		
		showGoods(){
			let text = '精准询价&厂家牌号选择按钮'
			log.info(text)
			uni.pageScrollTo({
			   scrollTop: 0,
			   duration: 0,
			})
			// if(this.specialId){
			// 	// this.specialId = ''
			// 	this.$refs.goodsSn.init(this.form.categoryId,'brandId',this.form.brandId);
			// }else{
			// 	this.$refs.goodsSn.init(this.form.categoryId);
			// }
			this.$refs.goodsSn.init(this.form.categoryId);
			
		},
		
		chooseColor(e){
			this.form.goodsColor = e;
		},
		
		chooseGoodsSn(e){
			this.form.brandId = e.brandId;
			this.form.brandName = e.brandName;
			this.form.goodsSn = e.goodsSn;
		},
		//选择品名
		chooseCategory(e,firstName,firstId){
			// console.log("e",e)
			this.firstName  = firstName
			this.firstId  = firstId
			this.form.categoryId = e.categoryId;
			this.form.categoryName = e.name;
			this.form.brandId = '';
			this.form.brandName = '';
			this.form.goodsSn = '';
			this.form.goodsColor = '';
			this.form.goodsFunction = '';
			this.defaultTime();
			// if(this.specialId){
			// 	this.specialId = ''
			// }
			if(this.form.categoryName != '' && (this.firstName.indexOf('原') != -1 || this.firstName.indexOf('改') != -1)){
				this.$refs.category.closeShow();
				this.showGoods()
			}else if(this.form.categoryName != '' && this.firstName.indexOf('定') != -1){
				this.$refs.category.closeShow();
				this.showAttr();
			}else if(this.form.categoryName != '' && this.firstName.indexOf('再') != -1){
				this.$refs.category.closeShow();
				this.showColor();
			}
			
		},
		blackCategory(){
			this.$refs.chooseAttr.closeShow();
			this.$refs.chooseColor.closeShow();
			this.$refs.goodsSn.closeShow();
			this.showCategory();
		},
		//显示品名
		showCategory(){
			let text = '精准询价&品名选择按钮'
			log.info(text)
			this.$refs.category.init();
		},
		//默认时间
		defaultTime(){
			
			let date = new Date();
			let i = 1
			if((this.firstName.indexOf('原') != -1 || this.firstName.indexOf('改') != -1 )){
				i = 2
			}else if(this.firstName.indexOf('定') != -1){
				i = 7
			}else if((this.firstName.indexOf('辅') != -1 || this.firstName.indexOf('再') != -1) ){
				i = 5
			}
			this.form.receiveDate= this.result(Number(date)+3*24*60*60*1000,'date');
			this.form.endTime= this.result(Number(date)+i*24*60*60*1000,'datetime')
		},
		//显示时间选择
		showDate(key){
			this.mode1 = key == 'receiveDate' ? 'date' : 'datetime';
			this.key = key;
			let oldFormNum = this.form[this.key];
			if(this.form[this.key] && this.mode1 == 'datetime'){
				oldFormNum = oldFormNum + ':00'
			}
			let date = this.form[this.key] ? new Date(oldFormNum) :new Date();
			let i = 1
			if((this.firstName.indexOf('原') != -1 || this.firstName.indexOf('改') != -1 )){
				i = 2
			}else if(this.firstName.indexOf('定') != -1){
				i = 7
			}else if((this.firstName.indexOf('辅') != -1 || this.firstName.indexOf('再') != -1) ){
				i = 5
			}
			
			let time = key == 'receiveDate' ? 3*24*60*60*1000 : i*24*60*60*1000;
			if(this.form[this.key] != ''){
				time = 0
			}
			this.value1 = Number(date) + time;
			this.showTime = true;
			let text =  key == 'receiveDate' ? '精准询价&交货日期选择按钮' : '精准询价&询价截止时间选择按钮';
			log.info(text)
		},
		confirmTime(e){
			this.form[this.key] = this.result(e.value, e.mode);
			this.showTime = false;
			let text = this.key == 'receiveDate' ? '精准询价&交货日期弹窗&' : '精准询价&询价截止时间&';
			text = text+this.form[this.key]
			log.info(text)
		},
		result(time, mode) {
			const timeFormat = uni.$u.timeFormat;	
			switch (mode) {
				case 'datetime':
					return timeFormat(time, 'yyyy-mm-dd hh')
				case 'date':
					return timeFormat(time, 'yyyy-mm-dd')
				
			}
		},
		getDataList() {
		  getAreaList().then((res) => {
		    this.dataTree = res;
		  })
		},
		
		onpopupopened() {
		  // console.log('popupopened');
		  let text = '精准询价&收货地址选择按钮';
		  log.info(text)
		},
		onpopupclosed() {
		  // console.log('popupclosed');
		},
		onchange(e) {
		  let ids = [];
		  let txts = [];
		  e.detail.value.forEach((item) => {
		    txts.push(item.text)
		    ids.push(item.value)
		  });
		  this.form.receiveAreaId = ids[2] ? ids[2] : ''
		  this.form.areaInfo = txts.join(" ")
		  log.info('精准询价&收货地址弹窗&'+this.form.areaInfo)
		},
	}
	

  }
</script>

<style lang="scss">
@import '@/style/common.scss';
.add-inquiry-page{
	background: linear-gradient(179deg, #FF5E01 0%, #F3F3F3 100%);
	background-size: 200rpx;
	padding:40rpx 20rpx;
	.inquiry-block{
		background: rgba(255,255,255,1) ;
		box-shadow: 0px 0px 10rpx rgba(0,0,0,0.06);
		border-radius: 18rpx;
		padding:30rpx;
		.inquiry-text{
			font-size: 24rpx;
			line-height: 40rpx;
			color: #000000;
		}
		.inquiry-history-list{
			max-height:100rpx;
			margin-top:30rpx;
			overflow: hidden;
			.list-item{
				height: 42rpx;
				line-height: 42rpx;
				background: rgba(245,245,245,1);
				border-radius: 9rpx;
				font-size: 22rpx;
				line-height: 36rpx;
				color: #8B8B8B;
				@include textoverflow(1);
				width:calc(50% - 10rpx);
				text-align: center;
				padding:0 24rpx;
				float:left;
				margin-right:16rpx;
				margin-bottom:16rpx;
			}
			.list-item:nth-child(2n+2){
				margin-right:0
			}
		}
		.inquiry-btn{
			font-size: 24rpx;
			line-height: 36rpx;
			color: #8B8B8B;
		    @include flexbox(center,center);
			margin-top:30rpx;
		}
		.index-form{
			padding-bottom:36rpx;
			.form-div{
				background: rgba(254,249,246,1);
				margin-bottom:20rpx;
			}
			.u-form-item__body__left__content__required{
				left:-9rpx;
				color:#FF0000
			}
			.u-form-item__body__left__content__label{
				padding-left:10rpx;
			}
			.u-form-item__body{
				padding:20rpx;
			}
			.u-form-item__body__left__content__label{
				color:#FF5E01
			}
			.u-radio-group--row{
				justify-content: flex-end;
			}
			.block-color .u-form-item__body__left__content__label{
				color:#000
			}
			.form-row{
				@include flexbox(flex-end,center);
			}
			.form-icon{
				width: 38rpx;
				height: 38rpx;
				background: rgba(255,242,235,1);
				border-radius: 50%;
				@include flexbox(center,center);
				flex:none;
				margin-left:20rpx;
			}
			.form-btn{
				@include flexbox(space-between,center);
				.form-btn-div{
					text-align: center;
					width: 300rpx;
				}
				.btn-label{
					font-size: 18rpx;
					color: #7A7A7A;
				}
			}
		}
	}
}
 
 
</style>